<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        {include file="public/link"}
    </head>
    
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" action="./modify.html" method="post">
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>标题</label>
                        <div class="layui-input-inline">
                            <input type="text" id="title" name="title" required="" value="{$info.title}" lay-verify="title" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="author" class="layui-form-label">
                            <span class="x-red">*</span>作者</label>
                        <div class="layui-input-inline">
                            <input type="text" id="author" name="author" required="" value="{$info.author}" lay-verify="author" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="read_num" class="layui-form-label">
                            <span class="x-red">*</span>浏览量</label>
                        <div class="layui-input-inline">
                            <input type="text" id="read_num" name="read_num" value="{$info.read_num}" required="" lay-verify="read_num" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red"></span>封面图</label>
                        <div class="layui-input-inline">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="tem_img_up">上传封面图</button>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" src="{$info.img}" style="width: 100%" id="tem_img">
                                    <p id="demoText"></p>
                                    <input type="hidden" name="img" value="{$info.img}" style="width: 500px" id="tem_input_img">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red"></span>轮播图</label>
                        <div class="layui-input-inline">
                            <button type="button" class="layui-btn" id="CarouselImg">上传轮播图</button>
                            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                预览图：
                                <div class="layui-upload-list" id="Carousel" style="width: 100%;">
                                    {foreach $info.image as $value}
                                    <img src="{$value}" style="width: 50px;" alt="">
                                    {/foreach}
                                    <input type="hidden" id="image" name="image" value="">
                                </div>
                            </blockquote>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="type" class="layui-form-label">
                            <span class="x-red">*</span>资讯分类</label>
                        <div class="layui-input-inline">
                            <select id="type" name="type" class="valid">
                                <option {if $info.type == 1} selected {/if} value="1">加盟攻略</option>
                                <option {if $info.type == 2} selected {/if} value="2">盟友探店</option>
                                <option {if $info.type == 3} selected {/if} value="3">加盟日记</option>
                                <option {if $info.type == 4} selected {/if} value="4">开店攻略</option>
                                <option {if $info.type == 5} selected {/if} value="5">创业指南</option>
                                <option {if $info.type == 6} selected {/if} value="6">选址技巧</option>
                                <option {if $info.type == 7} selected {/if} value="7">创业故事</option>
                                <option {if $info.type == 8} selected {/if} value="8">经营技巧</option>
                                <option {if $info.type == 9} selected {/if} value="9">活动专题</option>
                                <option {if $info.type == 10} selected {/if} value="10">如何去做加盟</option>
                                <option {if $info.type == 11} selected {/if} value="11">如何打造成一个好项目</option>
                                <option {if $info.type == 12} selected {/if} value="12">行业资讯</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="cate_id" class="layui-form-label">
                            <span class="x-red">*</span>选择标签</label>
                        <div class="layui-input-inline">
                            <select id="cate_id" name="cate_id" class="valid">
                                {foreach $cate as $key => $value}
                                <option {if $info.cate_id == $value.id} selected {/if} value="{$value.id}">{$value.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label for="sign" class="layui-form-label">描述</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" id="sign" name="sign" class="layui-textarea">{$info.sign}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label for="detail" class="layui-form-label">资讯内容</label>
                        <div class="layui-input-block">
                            <textarea id="detail" id="detail" name="detail" lay-verify="newsdetail">{$info.detail}</textarea>
                        </div>
                    </div>
                    <input type="hidden" name="id" value="{$info.id}">
                    <div class="layui-form-item">
                        <label for="" class="layui-form-label"></label>
                        <button class="layui-btn">增加</button>
                    </div>
        </form>
        </div>
        </div>
        <link href="__STATIC__/editor/Content/Layui-KnifeZ/css/layui.css" rel="stylesheet" />
        <script src="__STATIC__/editor/Content/Layui-KnifeZ/layui.js"></script>
        <script src="__STATIC__/editor/Content/ace/ace.js"></script>
        <script>
            layui.use('upload', function(){
                var $ = layui.jquery
                    ,upload = layui.upload;

                //普通图片上传
                var uploadInst = upload.render({
                    elem: '#tem_img_up'
                    ,url: "{:url('admin/common/uploadImage')}"
                    ,before: function(obj){
                        //预读本地文件示例，不支持ie8
                        obj.preview(function(index, file, result){
                            $('#tem_img').attr('src', result); //图片链接（base64）
                        });
                    }
                    ,done: function(res){
                        //如果上传失败
                        if(res.code > 0){
                            return layer.msg('上传失败');
                        }
                        //上传成功
                        $('#tem_input_img').attr('value',res.data.src); //图片链接（base64）
                    }
                    ,error: function(){
                        //演示失败状态，并实现重传
                        var demoText = $('#demoText');
                        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                        demoText.find('.demo-reload').on('click', function(){
                            uploadInst.upload();
                        });
                    }
                });
                //公司logo上传
                var uploadInst = upload.render({
                    elem: '#logo_up'
                    ,url: "{:url('admin/common/uploadImage')}"
                    ,before: function(obj){
                        //预读本地文件示例，不支持ie8
                        obj.preview(function(index, file, result){
                            $('#logo_img').attr('src', result); //图片链接（base64）
                        });
                    }
                    ,done: function(res){
                        //如果上传失败
                        if(res.code > 0){
                            return layer.msg('上传失败');
                        }
                        //上传成功
                        $('#input_logo').attr('value',res.data.src); //图片链接（base64）
                    }
                    ,error: function(){
                        //演示失败状态，并实现重传
                        var demoText = $('#logo');
                        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                        demoText.find('.logo-reload').on('click', function(){
                            uploadInst.upload();
                        });
                    }
                });
                //多图片上传
                upload.render({
                    elem: '#CarouselImg'
                    ,url: "{:url('admin/common/uploadImage')}"
                    ,multiple: true
                    ,before: function(obj){
                        //预读本地文件示例，不支持ie8
                        obj.preview(function(index, file, result){
                            $('#Carousel').append('<img src="'+ result +'" style="width: 50px;" alt="'+ file.name +'" class="layui-upload-img">')
                        });
                    }
                    ,done: function(res){
                        //上传完毕
                        $('#image').val($("#image").val()+res.data.src+",");

                    }
                });
            });

            layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;
                form.verify({
                    newsdetail: function(value){
                        this.sync(ieditor);
                        // console.log('value',value);
                    }
                });

                //监听提交
                form.on('submit(add)',
                function(data) {
                    var detail = $("#detail").val();
                    console.log('detail',detail)
                    console.log(data.field);
                    var field = data.field;
                    //发异步，把数据提交给php
                    $.ajax({
                        type: "POST",
                        url: "{:url('admin/news/modify')}",
                        data:{
                            field:field,
                        },
                        success: function(returnData){
                            console.log('returnData',returnData);
                            if(returnData.code == 200){
                                layer.alert("增加成功", {
                                        icon: 6
                                    },
                                    function() {
                                        // 获得frame索引
                                        var index = parent.layer.getFrameIndex(window.name);
                                        //关闭当前frame
                                        parent.layer.close(index);
                                    });
                            }else{
                                layer.alert("内部错误", {
                                        icon: 5
                                    },
                                    function() {
                                        // 获得frame索引
                                        var index = parent.layer.getFrameIndex(window.name);
                                        //关闭当前frame
                                        parent.layer.close(index);
                                    });
                            }
                        }
                    });

                    return false;
                });
                //动态行业分类
                form.on('select(cate_pid)', function(data){
                    var pid=data.value;
                    $.ajax({
                        type: "POST",
                        url: "{:url('admin/cate/getCateChildList')}",
                        data:{
                            pid:pid,
                        },
                        success: function(returnData){
                            // console.log('returnData',returnData);
                            if(returnData.code == 200){
                                $("#cate_id").html(false);
                                layui.each(returnData.data,function (index,item) {
                                    // console.log('item.id',item.id);
                                    // console.log('item.name',item.name);
                                    $("#cate_id").append("<option value='"+item.id+"'>"+item.name+"</option>");
                                });
                                layui.form.render('select');//渲染
                            }else{
                                layer.alert('内部错误');
                            }
                        }
                    });
                });
                //动态加盟区域 province
                form.on('select(province)', function(data){
                    var pid=data.value;
                    // console.log('pid',pid);
                    $.ajax({
                        type: "POST",
                        url: "{:url('admin/city/getCityDataList')}",
                        data:{
                            pid:pid,
                        },
                        success: function(returnData){
                            // console.log('returnData',returnData);
                            if(returnData.code == 200){
                                $("#city").html(false);
                                layui.each(returnData.data,function (index,item) {
                                    // console.log('item.id',item.id);
                                    // console.log('item.name',item.cityname);
                                    $("#city").append("<option value='"+item.cityname+"'>"+item.cityname+"</option>");
                                });
                                layui.form.render('select');//渲染
                            }else{
                                layer.alert('内部错误');
                            }
                        }
                    });
                });
            });
            layui.use(['laydate', 'form'],
                function() {
                    var laydate = layui.laydate;

                    //执行一个laydate实例
                    laydate.render({
                        elem: '#brand_make_time' //指定元素
                    });
                });

            layui.use(['layedit', 'layer', 'jquery'], function () {
                var $ = layui.jquery;
                var layedit = layui.layedit;
                layedit.set({
                    //暴露layupload参数设置接口 --详细查看layupload参数说明
                    uploadImage: {
                        url: "{:url('admin/common/uploadImage')}",
                        accept: 'image',
                        acceptMime: 'image/*',
                        exts: 'jpg|png|gif|bmp|jpeg',
                        size: '10240'
                    }
                    , uploadVideo: {
                        url: '/Attachment/LayUploadFile',
                        accept: 'video',
                        acceptMime: 'video/*',
                        exts: 'mp4|flv|avi|rm|rmvb',
                        size: '20480'
                    }
                    //右键删除图片/视频时的回调参数，post到后台删除服务器文件等操作，
                    //传递参数：
                    //图片： imgpath --图片路径
                    //视频： filepath --视频路径 imgpath --封面路径
                    , calldel: {
                        url: '/Attachment/DeleteFile'
                    }
                    //开发者模式 --默认为false
                    , devmode: true
                    //插入代码设置
                    , codeConfig: {
                        hide: true,  //是否显示编码语言选择框
                        default: 'javascript' //hide为true时的默认语言格式
                    }
                    , tool: [
                        'html', 'code', 'strong', 'italic', 'underline', 'del', 'addhr', '|', 'fontFomatt', 'colorpicker', 'face'
                        , '|', 'left', 'center', 'right', '|', 'link', 'unlink', 'image_alt', 'video', 'anchors'
                        , '|', 'fullScreen'
                    ]
                    , height: '90%'
                });
                const ieditor = layedit.build('detail');
            })

        </script>

    </body>

</html>